//
//  MANaviAnnotionView.m
//  SmartLife
//
//  Created by Lawrence on 15/10/27.
//  Copyright © 2015年 Lawrence. All rights reserved.
//

#import "MANaviAnnotionView.h"

#define naviButtonWidth 44
#define naviButtonHeight 74




@implementation NaviButton
-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        [self setBackgroundImage:[UIImage imageNamed:@"naviBackgroundNormal"] forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage imageNamed:@"naviBackgroundHightlighted"] forState:UIControlStateHighlighted];
        _carImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navi"] highlightedImage:nil];
        [self addSubview:_carImageView];
        
        
        //label
        _naviLabel=[[UILabel alloc] init];
        _naviLabel.text=NSLocalizedString(@"导航",nil);
        _naviLabel.font=[_naviLabel.font fontWithSize:9];
        _naviLabel.textColor=[UIColor whiteColor];
        [_naviLabel sizeToFit];
        
        [self addSubview:_naviLabel];
    }
    return self;
}

#define kMarginRatio 0.1
-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    _carImageView.center=CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.superview.frame)-CGRectGetHeight(_carImageView.frame)*(0.5+kMarginRatio));
    
    _naviLabel.center= CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.superview.frame) + CGRectGetHeight(_naviLabel.frame) * (0.5 + kMarginRatio));
}

@end

@implementation MANaviAnnotionView

-(id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
    
    
    self=[super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        NaviButton *naviButton=[[NaviButton alloc] initWithFrame:(CGRectMake(0,0,naviButtonWidth, naviButtonHeight))];
        self.leftCalloutAccessoryView=naviButton;
    }
    return self;
}


@end
